// AJAX support
var xmlHttp
var counter = 0

function getCharacters(title) {
	
	if ( title != 0 ) {
	    xmlHttp = getXmlHttpObject()
	
	    var url = "server/anime/characterlistdb.php"
	    url = url + "?title=" + title
	    
	    post( xmlHttp, url, showCharacters );
	} else {
		window.location.href = window.location.href;
	}
}

function showCharacters() {
    
    if (xmlHttp.readyState==4) {
            
        var characters = xmlHttp.responseText.split(",")
        var readSection = document.getElementById("readsection").cloneNode(true)
        readSection.id="namesection"
        readSection.style.display = "block"
        
        var nodes = readSection.childNodes
        var select
        for (i = 0; i < nodes.length; i++) {
            var name = nodes[i].name
        	if (name == "tempselect") {
        	    nodes[i].name="name";
        	    select = nodes[i]
        	}	
        }
        
        select.options[0] = new Option("Select a character","");
        for (i = 0; i < characters.length; i++) {
            select.options[i+1] = new Option(characters[i],characters[i])
        }
        
        var writeSection = document.getElementById("writesection")
      	var nameSection = document.getElementById("namesection")
      	if ( nameSection ) {
      	   writeSection.parentNode.removeChild(nameSection)
      	} 
        writeSection.parentNode.insertBefore(readSection,writeSection)        
    }
}

function getInfo(name) {

    xmlHttp = getXmlHttpObject()

    var url = "server/anime/characterinfodb.php"
    url = url + "?name=" + name
    
    post( xmlHttp, url, showInfo );   
}

function showInfo() {
	
    if (xmlHttp.readyState==4) {
	    document.getElementById("infosection").innerHTML=xmlHttp.responseText;   
    }
}